Conditions | 5 |
Paths | 24 |
Total Lines | 35 |
Code Lines | 22 |
Lines | 35 |
Ratio | 100 % |
Changes | 0 |
1 | View Code Duplication | import axios from 'axios' |
|
45 | async onSubmit() { |
||
46 | this.pending = true |
||
47 | let router = this.$router |
||
48 | let action = this.isNew |
||
49 | ? this.$app.route(`admin.${this.resourceRoute}.store`) |
||
50 | : this.$app.route(`admin.${this.resourceRoute}.update`, { |
||
51 | [this.modelName]: this.id |
||
52 | }) |
||
53 | |||
54 | let formData = this.$app.objectToFormData(this.model) |
||
55 | |||
56 | if (!this.isNew) { |
||
57 | formData.append('_method', 'PATCH') |
||
58 | } |
||
59 | |||
60 | try { |
||
61 | let { data } = await axios.post(action, formData) |
||
62 | this.pending = false |
||
63 | |||
64 | this.$app.noty[data.status](data.message) |
||
65 | if (this.listPath) { |
||
66 | router.push(this.listPath) |
||
67 | } |
||
68 | } catch (e) { |
||
69 | this.pending = false |
||
70 | |||
71 | // Validation errors |
||
72 | if (e.response.status === 422) { |
||
73 | this.validation = e.response.data |
||
74 | return |
||
75 | } |
||
76 | |||
77 | this.$app.error(e) |
||
78 | } |
||
79 | } |
||
80 | }, |
||
85 |